import req from "@/http"

export interface login_interface {
  userName: string
  password: string
}
export const login = async (data: login_interface) => {
  const { res, err, isSuccess } = await req({
    method: "post",
    url: "/login",
    params: data,
  })
  return isSuccess ? Promise.resolve(res) : Promise.reject(err)
}

export interface getStudentList_interface {
  stuSex: string
  stuName: string
  stuId: string
  pageNum: number
  pageSize: number
  isDelete: number
}

export interface getStudentList_Item {
  id?: string
  stuSex: string
  stuName: string
  stuClass: string
  stuCollege: string
  stuId: string
  stuPhone: string
  stuAge: string
  isDelete?: string
}
export interface getStudentList_res_interface {
  pageNum: number
  pageSize: number
  total: number
  totalPage: number
  list: Array<getStudentList_Item>
}

export const getStudentList = async (data: getStudentList_interface) => {
  const { res, err, isSuccess } = await req<getStudentList_res_interface>({
    method: "post",
    url: "/stuInfo/listPage",
    data,
  })

  return isSuccess ? Promise.resolve(res) : Promise.reject(err)
}

export const addStudent = async (data: Omit<getStudentList_Item, "id" | "isDelete">) => {
  const { res, err, isSuccess } = await req<null>({
    method: "post",
    url: "/stuInfo/insert",
    data,
  })

  return isSuccess ? Promise.resolve(res) : Promise.reject(err)
}

export const updateStudent = async (data: Omit<getStudentList_Item, "isDelete">) => {
  const { res, err, isSuccess } = await req<null>({
    method: "put",
    url: "/stuInfo/updateInfo",
    data,
  })

  return isSuccess ? Promise.resolve(res) : Promise.reject(err)
}

export const deleteStudent = async (id: string) => {
  const { res, err, isSuccess } = await req<null>({
    method: "delete",
    url: `/stuInfo/delInfo/${id}`,
  })

  return isSuccess ? Promise.resolve(res) : Promise.reject(err)
}

export interface getScoreList_interface {
  stuName: string
  stuId: string
  pageNum: number
  pageSize: number
  isDelete: number
}

export interface getScoreList_Item {
  id?: string
  stuName: string
  stuId: string
  chinese: string
  mathematics: string
  english: string
  physics: string
  organism: string
  chemistry: string
  isDelete?: string
}
export interface getScoreList_res_interface {
  pageNum: number
  pageSize: number
  total: number
  totalPage: number
  list: Array<getScoreList_Item>
}

export const getScoreList = async (data: getScoreList_interface) => {
  const { res, err, isSuccess } = await req<getScoreList_res_interface>({
    method: "post",
    url: "/stuGrade/listPage",
    data,
  })

  return isSuccess ? Promise.resolve(res) : Promise.reject(err)
}

export const addScore = async (data: Omit<getScoreList_Item, "id" | "isDelete">) => {
  const { res, err, isSuccess } = await req<null>({
    method: "post",
    url: "/stuGrade/insert",
    data,
  })

  return isSuccess ? Promise.resolve(res) : Promise.reject(err)
}

export const updateScore = async (data: Omit<getScoreList_Item, "isDelete">) => {
  const { res, err, isSuccess } = await req<null>({
    method: "put",
    url: "/stuGrade/updateInfo",
    data,
  })

  return isSuccess ? Promise.resolve(res) : Promise.reject(err)
}

export const deleteScore = async (id: string) => {
  const { res, err, isSuccess } = await req<null>({
    method: "delete",
    url: `/stuGrade/delInfo/${id}`,
  })

  return isSuccess ? Promise.resolve(res) : Promise.reject(err)
}
